import * as api from '../../service/api'

const state = {

  	memberList : {},
  	sellerSystemList : [],
  	sellerLevelList : [
  		{title : '全部分销级别', code : ''},
		{title : '一级', code : '1'},
		{title : '二级', code : '2'}
	],
	memberIncomeDetailsList : {},
	upLevel : {},
	downLevel : {},
	statistics : {},
}

const getters = {
	memberList : state => state.memberList,
	sellerSystemList : state => state.sellerSystemList,
	sellerLevelList : state => state.sellerLevelList,
	memberIncomeDetailsList : state => state.memberIncomeDetailsList,
	upLevel : state => state.upLevel,
	downLevel : state => state.downLevel,
	statistics : state => state.statistics,
}

const actions = {

	async getSellerSystemList ({ commit }, para) {
		let res = await api.sellerSystemList();
		console.log(res);
		if(res.errcode === 0){
			res.data.unshift({ title : '全部分销体系', code: '' });
			res.data.unshift({ title : '最高权限', code: '1' });
        	res.data.unshift({ title : '普通会员', code: '0' });
			commit('setSellerSystemList', res.data);
		}
	},


	async getMemberIncomeDetailsList ({ commit }, para) {
		let res = await api.memberIncomeDetailsList(
			para.pageNo,
			para.pageSize,
			para.start_time,
			para.end_time,
			para.nickname,
			para.code,
			para.type
		);
		console.log(res);

		if(res.errcode === 0){
			commit('setMemberIncomeDetailsList', res.data);
			para.cb(res.data);
		}else{
			if(para.err) para.err(res.errmsg);
		}
	},
}

const mutations = {
	setMemberList (state, obj) {
        state.memberList = obj;
    },
    setSellerSystemList (state, obj) {
        state.sellerSystemList = obj;
    },
    setMemberIncomeDetailsList (state, obj) {
        state.memberIncomeDetailsList = obj;
    },
    setUpLevel (state, obj) {
        state.upLevel = obj;
    },
    setDownLevel (state, obj) {
        state.downLevel = obj;
    },
    setStatistics (state, obj) {
        state.statistics = obj;
    },
    
}

export default {
  state,
  getters,
  actions,
  mutations
}
